package sort.leetcode.medium;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author bruin_du
 * @description 最小时间差
 * @date 2022/8/12 23:01
 **/
public class OfferII035_FindMinDifference {
    public int findMinDifference(List<String> timePoints) {
        int len = timePoints.size();
        List<Integer> list = new ArrayList<>();
        for (String time : timePoints) {
            String[] strings = time.split(":");
            int hour = Integer.parseInt(strings[0]);
            int minute = Integer.parseInt(strings[1]);
            list.add(hour * 60 + minute);
        }
        Collections.sort(list);
        int res = Integer.MAX_VALUE;
        for (int i = 0; i < list.size() - 1; i++) {
            res = Math.min(res, list.get(i + 1) - list.get(i));
        }
        res = Math.min(res, list.get(0) + 1440 - list.get(list.size() - 1));
        return res;
    }
}
